import aiohttp
import asyncio
import time

start = time.time()
async def request(url):
    async with aiohttp.ClientSession() as session:
        # get()、 post()
        # headers, params/data, proxy='http://ip:port'
        async with await session.get(url) as response:
            # text()返回字符串形式的响应数据
            # read()返回的二进制形式的响应数据
            # json()返回的就是json对象
            # 在获取响应数据操作之前之前，必须要await手动挂起
            page_text = await response.text()
            print(page_text)
urls = [
    'www.baidu.com',
    'www.sogou.com',
    'www.goubanjia.com'
]
# 任务列表：存放多个任务对象
stasks = []
for url in urls:
    c = request(url)
    task = asyncio.ensure_future(c)
    stasks.append(task)

end = time.time()
print('总耗时', end-start)